package com.sneakxy.cloudbase.platform.bean.dto;

import java.util.ArrayList;
import java.util.List;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;

import org.springframework.beans.BeanUtils;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.sneakxy.cloudbase.platform.bean.Account;
import com.sneakxy.cloudbase.platform.bean.ValidAdd;
import com.sneakxy.cloudbase.platform.bean.ValidEdit;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 账号信息DTO
 * @author 潜行的虚影
 * @see
 */
@Data
@ApiModel("账号信息")
@EqualsAndHashCode
@JsonIgnoreProperties(ignoreUnknown = true)
public class AccountDTO implements java.io.Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4774805751645680040L;

	@NotBlank(groups = {ValidEdit.class})
	@Size(max=32, groups = {ValidEdit.class})
	@ApiModelProperty("账号ID")
	private String id;

	@NotBlank(groups = {ValidAdd.class, ValidEdit.class})
	@Size(max=50, groups = {ValidAdd.class, ValidEdit.class})
	@ApiModelProperty("账号")
	private String account;

	@Size(max=255, groups = {ValidAdd.class, ValidEdit.class})
	@ApiModelProperty("作用域")
	private String host;

	@NotBlank(groups = {ValidAdd.class, ValidEdit.class})
	@Size(max=50, groups = {ValidAdd.class, ValidEdit.class})
	@ApiModelProperty("显示名，用于页面显示使用")
	private String displayName;

	@NotBlank(groups = {ValidAdd.class})
	@Size(max=32, groups = {ValidAdd.class, ValidEdit.class})
	@ApiModelProperty("密码")
	private String password;

	@ApiModelProperty("状态")
	private int status;

	@Size(max=100, groups = {ValidAdd.class, ValidEdit.class})
	@ApiModelProperty("备注")
	private String memo;

	@ApiModelProperty("创建时间")
	private String createtime;

	@ApiModelProperty("更新时间")
	private String updatetime;

	public static AccountDTO from(Account entity) {
		AccountDTO result = new AccountDTO();
		BeanUtils.copyProperties(entity, result);
		return result;
	}
	
	public static List<AccountDTO> from(List<Account> list) {
		List<AccountDTO> result = new ArrayList<>(list.size());
		list.forEach(entity -> {
			result.add(from(entity));
		});
		return result;
	}
	
	public static Account to(AccountDTO entity) {
		Account result = new Account();
		BeanUtils.copyProperties(entity, result);
		return result;
	}
	
	public static List<Account> to(List<AccountDTO> list) {
		List<Account> result = new ArrayList<>(list.size());
		list.forEach(entity -> {
			result.add(to(entity));
		});
		return result;
	}

}
